package com.ryenlii.datatrans.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.ryenlii.datatrans.entity.dto.DeviceRecordDto;
import com.ryenlii.datatrans.entity.DeviceRecord;
import com.ryenlii.datatrans.entity.DeviceRecordInfo;
import com.ryenlii.datatrans.mapper.mysql.DeviceRecordMapper;
import com.ryenlii.datatrans.service.DeviceRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 设备推送信息表 服务实现类
 * </p>
 *
 * @author zhengwen
 * @since 2023-02-03
 */
@Service
public class DeviceRecordServiceImpl extends ServiceImpl<DeviceRecordMapper, DeviceRecord> implements DeviceRecordService {

    @Autowired
    private DeviceRecordMapper deviceRecordMapper;

    @Override
    public IPage<DeviceRecordDto> selectPage(Page page, DeviceRecord customQueryParams) {
        QueryWrapper<DeviceRecord> qw = new QueryWrapper<>();
        IPage<DeviceRecordDto> records = deviceRecordMapper.selectPage(page, qw);
        //IPage<Student> records = deviceRecordMapper.selectStudentPage(page, customQueryParams);

        return records;

    }

    @Override
    public IPage<DeviceRecordDto> getPageUseJoin(Page page, DeviceRecord customQueryParams) {
        //分页查询
        IPage<DeviceRecordDto> list = deviceRecordMapper.selectJoinPage(page, DeviceRecordDto.class,
                new MPJLambdaWrapper<DeviceRecord>()
                        .selectAll(DeviceRecord.class)
                        //子查询
                        .selectCollection(DeviceRecordInfo.class, DeviceRecordDto::getRecordInfoList)
                        .leftJoin(DeviceRecordInfo.class, DeviceRecordInfo::getRecordId, DeviceRecord::getId));

        /*QueryWrapper<DeviceRecord> queryWrapper = new QueryWrapper<>();
        IPage<DeviceRecordDto> list = deviceRecordMapper.selectPage(page,queryWrapper);*/
        //IPage<DeviceRecordDto> list = deviceRecordMapper.selectListBy(page,customQueryParams);

        return list;
    }
}
